package sg.edu.nus.iss.billing.gui;

// Author: Tan Pic Cheng

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JPanel;

public abstract class DefaultFunctionPanel extends JPanel{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -525235180232648949L;
	private JPanel topPanel;
	private JPanel bottomPanel;
	private JPanel actionButtonPanel;
	
	public DefaultFunctionPanel(){
		setPreferredSize(new Dimension((int)(MainFrame.WIDTH * 0.80), MainFrame.HEIGHT));
		setLayout(new BorderLayout());
	}
	
	public JPanel getBottomPanel() {
		return this.bottomPanel;
	}
	
	public JPanel getTopPanel() {
		return this.topPanel;
	}
	
	public JPanel getActionButtonPanel() {
		return this.actionButtonPanel;
	}
	
	public void init(String option){
		this.topPanel = createTopPanel();
		
		if(this.topPanel != null){
		   topPanel.setPreferredSize(new Dimension(800, 140));
		   add(this.topPanel,BorderLayout.NORTH);
		}
		
		if ("TOPONLY".equals(option)) {
			return;
		}
	
		this.bottomPanel = createBottomPanel();
		this.actionButtonPanel = createActionButtonsPanel();
		if(this.bottomPanel != null){
			bottomPanel.setPreferredSize(new Dimension(800, 600));
			add(this.bottomPanel, BorderLayout.CENTER);
		}
		if(this.actionButtonPanel != null)
			add(this.actionButtonPanel, BorderLayout.SOUTH);	
	}
	
	public void refreshBottomPanel(JPanel panel) {
		if (this.bottomPanel != null) {
			remove(this.bottomPanel);
		}
		this.bottomPanel = panel;
		this.bottomPanel.setPreferredSize(new Dimension(800, 600));
		add(this.bottomPanel, BorderLayout.CENTER);
		this.revalidate();
	}
	
	public void refreshBottomPanel() {
		refreshBottomPanel(createBottomPanel());
	}

	public void refreshActionButtonPanel(JPanel panel) {
		if (this.actionButtonPanel != null) {
			remove(this.actionButtonPanel);
		}
		this.actionButtonPanel = panel;
		if (this.actionButtonPanel != null) {
			add(this.actionButtonPanel, BorderLayout.SOUTH);
		}
		this.revalidate();
	}

	public void refreshActionButtonPanel() {
	  refreshActionButtonPanel(createActionButtonsPanel());
	}
	
	public abstract JPanel createTopPanel();
	public abstract JPanel createBottomPanel();	
	public abstract JPanel createActionButtonsPanel();
	
}
